<?php

/**
 * UserIdentity represents the data needed to identity a user.
 * It contains the authentication method that checks if the provided
 * data can identity the user.
 */
class UserIdentity extends CUserIdentity
{
        public $group_id;
        public $user_json;
        public $name;
	/**
	 * Authenticates a user.
	 * The example implementation makes sure if the username and password
	 * are both 'demo'.
	 * In practical applications, this should be changed to authenticate
	 * against some persistent user identity storage (e.g. database).
	 * @return boolean whether authentication succeeds.
	 */
	public function authenticate()
	{
            
            try{
                $connection=Yii::app()->db;   // assuming you have configured a "db" connection
                $query="SELECT * FROM ls_users   WHERE ls_users.username='" .$this->username."'";
                $command=$connection->createCommand($query);
                $dataReader=$command->query();
                $rows_user = array();
                while(($row=$dataReader->read())!==false) {
                    $rows_user[]=$row;
                }
                $data=$rows_user[0];
		if($data["password"]!==$this->password)
			$this->errorCode=self::ERROR_PASSWORD_INVALID;
		else{
			$this->errorCode=self::ERROR_NONE;
                        $this->user_json=$data;
                        $this->group_id=$data["group_id"];
                        $this->name=$data["name"];
                        //get information
                }
		return !$this->errorCode;
            }catch(Exception $e){

            }            


	}
}